package cn.jorian.framework.service.impl;

import cn.jorian.framework.bean.DataBean;
import cn.jorian.framework.bean.OutboundBackBean;
import cn.jorian.framework.bean.ResponseResult;
import cn.jorian.framework.net.NetManager;
import cn.jorian.framework.service.IOutdocBackService;
import cn.jorian.framework.util.ParamUtil;
import org.springframework.stereotype.Service;
import retrofit2.Response;

import java.io.IOException;
import java.util.UUID;

@Service
public class OutdocBackServiceImpl implements IOutdocBackService {

    @Override
    public ResponseResult outdocBack() {

        OutboundBackBean outboundBackBean = new OutboundBackBean();
        outboundBackBean.setOwnerCode("19940");
        outboundBackBean.setOrderNo("540530");
        outboundBackBean.setBusinessType("246");
        outboundBackBean.setOrderTime("2023/02/07");
        outboundBackBean.setOmsOrderNo("12345");


        OutboundBackBean.DtlBean dtlBean = new OutboundBackBean.DtlBean();
        dtlBean.setOrderDtlNo("12458890");
        dtlBean.setOmsOrderDtlNo("121212");
        dtlBean.setOwnerOgoodsCode("227929");
        dtlBean.setCommonName("葫芦岛UAT测试品（地采）");
        dtlBean.setBatchNbr("20240911");
        dtlBean.setPrdDate("2024-09-11");
        dtlBean.setValidDate("2024-09-21");
        dtlBean.setCount(5.0);
        dtlBean.setGoodsStatus("-1");
//        dtlBean.setBusinessType(inboundBackBean.getBusinessType());
//        dtlBean.setOrderNo(inboundBackBean.getOrderNo());
//        dtlBean.setOmsOrderNo(inboundBackBean.getOmsOrderNo());

        outboundBackBean.addList(dtlBean);


        //data
        DataBean<OutboundBackBean> dataBean = new DataBean<>();
        dataBean.setInterfaceType("Outbound_Back");
        dataBean.setChannelType("cdfy-erp");
        dataBean.setInterfaceNbr(UUID.randomUUID().toString());
        dataBean.addRecord(outboundBackBean);

        try {
            //同步post请求
            Response<ResponseResult> response = NetManager.newInstance().getServiceApi().indocBack(ParamUtil.getParam(dataBean)).execute();
            ResponseResult result = response.body();
            return result;
        } catch (IOException e) {
            e.printStackTrace();
            return ResponseResult.fail(e.getMessage());
        }

    }
}
